import json
import requests
from datetime import datetime, timedelta
from urllib.parse import urlencode


class MySession(requests.Session):
    def request(self, *args, **kwargs):
        kwargs.setdefault('timeout', 5)
        return super(MySession, self).request(*args, **kwargs)

def lis_new(pid, users):

    headers = {
                "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36",
                "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
                "X-Requested-With":"XMLHttpRequest",
                "Accept": "application/json, text/javascript, */*; q=0.01",
            }
    # 获取授权
    url_auth = "http://10.68.60.237/ppm/Login.aspx"
    data_auth = {
        "ajaxMethod":"ajaxHttpPost",
        "FUSERID":"02808",
        "FPASSWORD":"3",
        "FSYN":"0",
        "FTB":False,
    }
    # data_auth = urlencode(data_auth)
    data_auth = json.dumps(data_auth)
    a = users.post(url_auth, headers=headers, data=data_auth)
    print(users.cookies.items())

    url_index = "http://10.68.60.237/ppm/Index.aspx"
    b = users.get(url_index, headers=headers, )
    
    print(users.cookies.items())
    
    post_data_url = "http://10.68.60.237/ppm/MRTB001.aspx?ajaxMethod=ajaxScan&BCODE=%s&wh_crt=A070112&wh_next=8888&futype=T001&FYJ=&FYJR=&_=1691482366171" % str(pid)
    post_data_url_cancel = "http://10.68.60.237/ppm/MRTB001.aspx?ajaxMethod=ajaxDelete&fpid=%s&wh_crt=A070112&futype=T001&_=1691482366172" % str(pid)

    post_data_out = {
        "ajaxMethod":"ajaxScan",
        "BCODE":str(pid),
        "wh_crt":"A070112",
        "wh_next":"8888",
        "futype":"T001",
        "FYJ":"",
        "FYJR":"",
        "_":"1691467189180",
    }
    post_data_cancel = {
        "ajaxMethod":"ajaxDelete",
        "fpid":str(pid),
        "wh_crt":"A070112",
        "futype":"T001",
        "_":"1691467189181",
    }

    # get_post_data_out = users.get(
    #      post_data_url_cancel,
       
    #     headers=headers
    #  )
    # if get_post_data_out.status_code != 200:
    #     raise Exception('网络访问失败')
    
    # print(get_post_data_out.text)

if __name__ == "__main__":

    users = MySession()
    print(lis_new(2023000048,users))
